package santiago.codebase;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Set;
import santiago.domain.CardinalPoint;
import santiago.domain.DifficultyLevel;
import santiago.domain.Game;
import santiago.domain.Player;
import santiago.exception.AlreadyInGameException;
import santiago.exception.ExistingItemException;
import santiago.exception.InvalidAmountException;
import santiago.exception.MaximalPlayerCountReachedException;
import santiago.exception.NoSuchGameException;
import santiago.exception.NotEnoughCashException;
import santiago.exception.NotEnoughPlayerException;

public interface IServer extends Remote {

    /**
     * Allow a player to join a server
     *
     * @param Client
     * @throws RemoteException
     * @throws ExistingItemException
     */
    void connect(String Login, IClient Client) throws RemoteException, ExistingItemException;

    /**
     * Allow a player to leave a server. If this player is playing a game, he
     * will be disconnected
     *
     * @param Login
     * @throws RemoteException
     */
    void disconnect(String Login) throws RemoteException;

    void createGame(String GameName, int PlayerNbr, DifficultyLevel Level, boolean DisplayCash, boolean PalmTree) throws RemoteException, ExistingItemException;

    /**
     * Allow a player to join a Game
     *
     * @param GameName
     * @param Login
     * @return
     * @throws RemoteException
     * @throws ExistingItemException
     * @throws MaximalPlayerCountReachedException
     * @throws AlreadyInGameException
     * @throws NoSuchGameException
     */
    void joinGame(String GameName, String Login) throws RemoteException, ExistingItemException, MaximalPlayerCountReachedException, AlreadyInGameException, NoSuchGameException, NotEnoughPlayerException;

    /**
     * Allow a player to leave his current Game.
     *
     * @param Login
     * @param GameName
     * @throws RemoteException
     * @throws NoSuchGameException
     */
    void leaveGame(String Login, String GameName) throws RemoteException, NoSuchGameException;

    void bid(String Login, int Amount) throws RemoteException, InvalidAmountException, NotEnoughCashException;

    void placePlantation(String Login, int NodeIndex, int PlantationIndex, CardinalPoint Location) throws RemoteException;

    /**
     * Allow the given player to send a message in his current game
     *
     * @param Login Player name
     * @param Message
     * @throws RemoteException
     */
    void sendMessage(String Login, String Message) throws RemoteException;

    /**
     * Allow a player to get the list of all the games available on the server
     *
     * @return
     * @throws RemoteException
     */
    Set<Game> getGames() throws RemoteException;

    Player getPlayer(String Login) throws RemoteException;

    /**
     * Allow a player to get the list of players of a game
     *
     * @param GameName
     * @return
     */
    Collection<Player> getPlayers(String GameName) throws RemoteException, NoSuchGameException;

    Game getGame(String GameName) throws RemoteException;
}
